package binary_tree.Leetcode;

/**
 * 判断一棵树是否为轴对称
 * 左树t1和右树t2镜像 t1.val=t2.val&&t1.left和t2.right镜像 &&t1.right和 t2.left镜像
 */
public class Num101_SymmetricTree {
    public boolean isSymmetric(TreeNode root) {
        if(root==null){
            return true;
        }
        return isMirror(root.left,root.right);
    }

    private boolean isMirror(TreeNode left, TreeNode right) {
        if(left==null&&right==null){
            return true;
        }
        if (left==null||right==null){
            return false;
        }
        if(left.val!=right.val){
            return false;
        }
        return isMirror(left.right,right.left)&& isMirror(left.left,right.right);
    }
}
